package kr.couponplay.android.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import android.content.Context;

public class DisplayUtils {
	private static final float DEFAULT_HDIP_DENSITY_SCALE = 1.5f;

	public static int dPFromPixel(Context context, int pixel) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pixel / DEFAULT_HDIP_DENSITY_SCALE * scale);
	}

	public static int pixelFromDP(Context context, int dp) {
		float den = context.getResources().getDisplayMetrics().density;
		return (int) (dp * den+0.5);
	}
	
	public static int widthPixels(Context context) {
		return context.getResources().getDisplayMetrics().widthPixels;
	}
	
	public static String numFormat(int num) {
		DecimalFormat df = new DecimalFormat("#,##0");
		return df.format(num);
	}
	
	public static String dateFormat(long now) {
		Date date = new Date(now);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		return format.format(date);
	}
}
